home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ML_BME1.ZIP / PLASMA / GENP5.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-21  |  1.9 KB  |  79 lines

  1. // *************************************************************************
  2. //  Plasma cloud generator
  3. //  by Maple Leaf, Dec 1996
  4. //  -----------------------------------------------------------------------
  5. //  No rights reserved
  6. // *************************************************************************
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <math.h>
  11.  
  12. void    main()
  13. {
  14.     float    x,y,count,i;
  15.     int    lead,offset;
  16.     FILE    *fp;
  17.     unsigned char value;
  18.  
  19.     printf("\nPlasma generator, by Maple Leaf, 1996\n\nProcessing ...!\n");
  20.  
  21.     if (!(fp=fopen("PLASMA.DAT","wb")))
  22.     {
  23.         printf("\7Cant open output file PLASMA.DAT\n");
  24.         exit(255);
  25.     }
  26.  
  27.     /* First generate the plasma map.  This is effectively just an
  28.        arbitrary function of x and y which gives a smooth but
  29.        non-uniform surface */
  30.  
  31.     printf("\nGenerating main map ");
  32.     for (y=0;y<300;y++) {
  33.       for (x=0;x<512;x++)
  34.       {
  35.         value=64+ 7*( sin(x/20) + cos(y/180) +
  36.                   cos(x/40) + sin((x-y)/70) +
  37.                   sin((x+2*y)/70) +
  38.                   sin(hypot(256-x,150-y/8)/10) -
  39.                   cos((x*4-y*2)/70) +
  40.                   sin(2*cos((y*4-x*2)/100))
  41.                   );
  42.         fputc(value,fp);
  43.       }
  44.       if ((int)y % 30 == 0) printf(".");
  45.     }
  46.  
  47.     printf("\nGenerating movement path ...");
  48.     /* Then arbitrary movement for two pointers */
  49.  
  50.     for (count=0;count<10000;count++)
  51.     {
  52.         lead=           96+92*cos(count/32)
  53.              +512*(int)(48+47*sin(count/16));
  54.         offset=         96+92*sin(count/21)
  55.              +512*(int)(48+47*cos(count/24))
  56.              -lead;
  57.         fwrite(&lead,2,1,fp);
  58.         fwrite(&offset,2,1,fp);
  59.     }
  60.  
  61.     printf("\nGenerating palette ...\n");
  62.     /* And a smooth transition colour lookup table */
  63.  
  64.     for (i=-256; i<256*39; i++)
  65.         if (i<0)
  66.         {
  67.             fputc(0,fp);
  68.             fputc(0,fp);
  69.             fputc(0,fp);
  70.         }
  71.         else
  72.         {
  73.             fputc((sin(i/30)*cos(i/50)*31+31),fp);
  74.             fputc((sin(i/400)*cos(i/100)*31+31),fp);
  75.             fputc((cos(i/200)*sin(i/300)*31+31),fp);
  76.         }
  77.     fclose(fp);
  78. }
  79.